package com.mall.canal.listener;

import com.mall.goods.feign.SkuFeign;
import com.mall.goods.model.AdItems;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

import javax.annotation.Resource;

@Component
@CanalTable(value = "ad_items")
public class AdItemsListener implements EntryHandler<AdItems> {

    @Resource
    private SkuFeign skuFeign;

    @Override
    public void insert(AdItems adItems) {
        skuFeign.updateTypeItems(adItems.getType());;
    }

    @Override
    public void update(AdItems before, AdItems after) {
        if(before.getType() != after.getType()){
            skuFeign.updateTypeItems(before.getType());;
        }
        skuFeign.updateTypeItems(after.getType());;
    }

    @Override
    public void delete(AdItems adItems) {
        System.out.printf("delete===="+adItems);
        skuFeign.delTypeItems(adItems.getType());;
    }
}
